package com.tanhua.model.vo;

import com.tanhua.model.domain.Announcement;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.time.LocalDateTime;
import java.time.ZoneId;

@Data
@AllArgsConstructor  //满参构造方法
@NoArgsConstructor   //无参构造方法
public class AnnouncementVo {

    private String id;

    private String title;

    private String description;


    private LocalDateTime createDate;


    public static AnnouncementVo init(Announcement announcement) {

        AnnouncementVo announcementVo = new AnnouncementVo();
        BeanUtils.copyProperties(announcement, announcementVo);
        announcementVo.setId(announcement.getId().toString());
        announcementVo.setCreateDate(LocalDateTime.ofInstant(announcement.getUpdated().toInstant(), ZoneId.systemDefault()));
        return announcementVo;
    }

}